<template>
    <div class="redirect">
        <div>
            <img :src="imgSrc[1]" alt="hello" style="width: 100%">
        </div>
        <div>
            <van-button type="default" @click="handleRedirect('0')">登录</van-button>
            <van-button type="default" @click="handleRedirect('1')">个人中心</van-button>
            <van-button type="default" @click="handleRedirect('2')">礼包订单列表</van-button>
            <van-button type="default" @click="handleRedirect('3')">夺宝</van-button>
        </div>
        <div>
            <div v-for="item in goodsList"
                 :key="item.goodsId" @click="toGoodsDetail(item.goodsId)" style="margin: 10px;">
                {{item.goodsName}}
            </div>
            {{userInfo.nickName}}
        </div>
    </div>
</template>

<script>
    export default {
        name: 'redirect',
        components: {},

        data() {
            return {
                userInfo:this.$store.state.userInfo,
                imgSrc: [
                    require("@img/app-logo.png"),
                    require('@img/12.jpeg')
                ],
                page: this.$global.page,
                pages: this.$global.pages,
                size: this.$global.size,
                goodsList: [],
            }
        },

        created() {
            this.initData()
        },
        computed: {},
        watch: {},
        methods: {
            handleRedirect(value) {
                switch (value) {
                    case "0":
                        this.$router.push({path: "/login"});
                        break;
                    case "1":
                        this.$router.push({path: "/personalCenter"});
                        break;
                    case "2":
                        this.$router.push({path: "/product/OrderList"});
                        break;
                    case "3":
                        this.$router.push({path: "/treasure/index"});
                        break;
                    default:
                        this.$router.push({path: "/index"});
                        break;
                }
            },
            //初始化数据
            initData() {
                this.getGoodsList()
            },
            //获取商品列表
            getGoodsList() {
                this.$api.getGoodsInfoList({
                    page: this.page,
                    size: 30
                }).then(res => {
                    let result = this.$resArr(res);
                    //console.log(result)
                    if(result) {
                        this.goodsList = result.list;
                        this.pages = parseInt(result.pages);
                    }
                })
            },
            toGoodsDetail(goodsId) {
                this.$router.push({
                    path: "/goods/goodsDetail",
                    query: {
                        goodsId: goodsId,
                        inviteNum: 123456
                    }
                })
            },
            toLogin() {
                this.$router.push({path: "/login"})
            },
            userCenter(){
                this.$router.push({path: "/userCenter"})
            }
        }
    }
</script>

<style lang="scss" scoped>
    .redirect {

    }
</style>
